/**
  ******************************************************************************
  * File Name          : tskctrl.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "tskcfg.h"
#include "sensor.h"
#include "gui.h"
#include "dclcd.h"
#include "ethernet.h"
#include "produp.h"
#include "prodrt.h"
#include "mbtcp.h"
#include "sddriver.h"

QueueHandle_t        storage_qhd = NULL;
static StaticQueue_t storage_que_stru;
static uint8_t       storage_que_area[STORAGE_QUE_LENGTH * STORAGE_QUE_ITEMSIZE];

QueueHandle_t        sd_drvmsg_qhd = NULL;
static StaticQueue_t sd_drvmsg_questru;
static uint8_t       sd_drvmsg_quearea[SD_DRVMSG_QUE_LENGTH * SD_DRVMSG_QUE_ITEMSIZE];

QueueHandle_t        sensor_recv_qhd = NULL;
static StaticQueue_t sensor_recv_questru;
static uint8_t       sensor_recv_quearea[SENSOR_RECV_QUE_LENGTH * SENSOR_RECV_QUE_ITEMSIZE];

QueueHandle_t        gui_cmd_qhd = NULL;
static StaticQueue_t gui_cmd_stru;
static uint8_t       gui_cmd_area[GUI_CMD_QUE_LENGTH * GUI_CMD_QUE_ITEMSIZE];

QueueHandle_t        dclcd_recv_qhd = NULL;
static StaticQueue_t dclcd_recv_questru;
static uint8_t       dclcd_recv_quearea[DCLCD_RECV_QUE_LENGTH * DCLCD_RECV_QUE_ITEMSIZE];

QueueHandle_t        dclcd_send_qhd = NULL;
static StaticQueue_t dclcd_send_questru;
static uint8_t       dclcd_send_quearea[DCLCD_SEND_QUE_LENGTH * DCLCD_SEND_QUE_ITEMSIZE];

QueueHandle_t        irkey_wave_qhd = NULL;
static StaticQueue_t irkey_wave_questru;
static uint8_t       irkey_wave_quearea[IRKEY_WAVE_QUE_LENGTH * IRKEY_WAVE_QUE_ITEMSIZE];

QueueHandle_t        ethernet_ctrl_qhd = NULL;
static StaticQueue_t ethernet_ctrl_questru;
static uint8_t       ethernet_ctrl_quearea[ETHERNET_CTRL_QUE_LENGTH * ETHERNET_CTRL_QUE_ITEMSIZE];

QueueHandle_t        ethernet_send_qhd = NULL;
static StaticQueue_t ethernet_send_questru;
static uint8_t       ethernet_send_quearea[ETHERNET_SEND_QUE_LENGTH * ETHERNET_SEND_QUE_ITEMSIZE];

QueueHandle_t        ethernet_isr_qhd = NULL;
static StaticQueue_t ethernet_isr_questru;
static uint8_t       ethernet_isr_quearea[ETHERNET_ISR_QUE_LENGTH * ETHERNET_ISR_QUE_ITEMSIZE];

QueueHandle_t        prod_database_qhd = NULL;
static StaticQueue_t prod_database_questru;
static uint8_t       prod_database_quearea[PROD_DATABASE_QUE_LENGTH * PROD_DATABASE_QUE_ITEMSIZE];

QueueHandle_t        produp_ethfb_qhd[2]= {NULL, NULL};
static StaticQueue_t produp_ethfb_ctrl_questru;
static uint8_t       produp_ethfb_ctrl_quearea[PRODUP_ETHFB_CTRL_QUE_LENGTH * PRODUP_ETHFB_CTRL_QUE_ITEMSIZE];
static StaticQueue_t produp_ethfb_data_questru;
static uint8_t       produp_ethfb_data_quearea[PRODUP_ETHFB_DATA_QUE_LENGTH * PRODUP_ETHFB_DATA_QUE_ITEMSIZE];

QueueHandle_t        prodrt_ethfb_qhd[2]= {NULL, NULL};
static StaticQueue_t prodrt_ethfb_ctrl_questru;
static uint8_t       prodrt_ethfb_ctrl_quearea[PRODRT_ETHFB_CTRL_QUE_LENGTH * PRODRT_ETHFB_CTRL_QUE_ITEMSIZE];
static StaticQueue_t prodrt_ethfb_data_questru;
static uint8_t       prodrt_ethfb_data_quearea[PRODRT_ETHFB_DATA_QUE_LENGTH * PRODRT_ETHFB_DATA_QUE_ITEMSIZE];

QueueHandle_t        mbtcp_ethfb_qhd[2]= {NULL, NULL};
static StaticQueue_t mbtcp_ethfb_ctrl_questru;
static uint8_t       mbtcp_ethfb_ctrl_quearea[MBTCP_ETHFB_CTRL_QUE_LENGTH * MBTCP_ETHFB_CTRL_QUE_ITEMSIZE];
static StaticQueue_t mbtcp_ethfb_data_questru;
static uint8_t       mbtcp_ethfb_data_quearea[MBTCP_ETHFB_DATA_QUE_LENGTH * MBTCP_ETHFB_DATA_QUE_ITEMSIZE];

QueueSetHandle_t ethernet_qshd     = NULL;   /* 以太网综合控制 队列集 */
QueueSetHandle_t produp_ethfb_qshd = NULL;   /* 间隔产量以太网收发控制 队列集 */
QueueSetHandle_t prodrt_ethfb_qshd = NULL;   /* 实时产量以太网收发控制 队列集 */
QueueSetHandle_t mbtcp_ethfb_qshd  = NULL;   /* Modbus TCP 服务器以太网收发控制 队列集 */

void app_queue_create(void)
{
  sd_drvmsg_qhd = xQueueCreateStatic(SD_DRVMSG_QUE_LENGTH, SD_DRVMSG_QUE_ITEMSIZE, sd_drvmsg_quearea, &sd_drvmsg_questru);
  configASSERT(sd_drvmsg_qhd);

  sensor_recv_qhd = xQueueCreateStatic(SENSOR_RECV_QUE_LENGTH, SENSOR_RECV_QUE_ITEMSIZE, sensor_recv_quearea, &sensor_recv_questru);
  configASSERT(sensor_recv_qhd);

  gui_cmd_qhd = xQueueCreateStatic(GUI_CMD_QUE_LENGTH, GUI_CMD_QUE_ITEMSIZE, gui_cmd_area, &gui_cmd_stru);
  configASSERT(gui_cmd_qhd);

  dclcd_recv_qhd = xQueueCreateStatic(DCLCD_RECV_QUE_LENGTH, DCLCD_RECV_QUE_ITEMSIZE, dclcd_recv_quearea, &dclcd_recv_questru);
  configASSERT(dclcd_recv_qhd);

  dclcd_send_qhd = xQueueCreateStatic(DCLCD_SEND_QUE_LENGTH, DCLCD_SEND_QUE_ITEMSIZE, dclcd_send_quearea, &dclcd_send_questru);
  configASSERT(dclcd_send_qhd);

  irkey_wave_qhd = xQueueCreateStatic(IRKEY_WAVE_QUE_LENGTH, IRKEY_WAVE_QUE_ITEMSIZE, irkey_wave_quearea, &irkey_wave_questru);
  configASSERT(irkey_wave_qhd);

  ethernet_ctrl_qhd = xQueueCreateStatic(ETHERNET_CTRL_QUE_LENGTH, ETHERNET_CTRL_QUE_ITEMSIZE, ethernet_ctrl_quearea, &ethernet_ctrl_questru);
  configASSERT(ethernet_ctrl_qhd);

  ethernet_send_qhd = xQueueCreateStatic(ETHERNET_SEND_QUE_LENGTH, ETHERNET_SEND_QUE_ITEMSIZE, ethernet_send_quearea, &ethernet_send_questru);
  configASSERT(ethernet_send_qhd);

  ethernet_isr_qhd = xQueueCreateStatic(ETHERNET_ISR_QUE_LENGTH, ETHERNET_ISR_QUE_ITEMSIZE, ethernet_isr_quearea, &ethernet_isr_questru);
  configASSERT(ethernet_isr_qhd);

  storage_qhd = xQueueCreateStatic(STORAGE_QUE_LENGTH, STORAGE_QUE_ITEMSIZE, storage_que_area, &storage_que_stru);
  configASSERT(storage_qhd);

  /* 间隔产量数据入库队列 */
  prod_database_qhd = xQueueCreateStatic(PROD_DATABASE_QUE_LENGTH, PROD_DATABASE_QUE_ITEMSIZE, prod_database_quearea, &prod_database_questru);
  configASSERT(prod_database_qhd);

  /* 间隔产量上传(主服务器) 网络控制队列 */
  produp_ethfb_qhd[CQUE] = xQueueCreateStatic(PRODUP_ETHFB_CTRL_QUE_LENGTH, PRODUP_ETHFB_CTRL_QUE_ITEMSIZE, produp_ethfb_ctrl_quearea, &produp_ethfb_ctrl_questru);
  configASSERT(produp_ethfb_qhd[CQUE]);

  /* 间隔产量上传(主服务器) 网络接收队列 */
  produp_ethfb_qhd[DQUE] = xQueueCreateStatic(PRODUP_ETHFB_DATA_QUE_LENGTH, PRODUP_ETHFB_DATA_QUE_ITEMSIZE, produp_ethfb_data_quearea, &produp_ethfb_data_questru);
  configASSERT(produp_ethfb_qhd[DQUE]);

  /* 实时产量上传(AB服务器) 网络控制队列 */
  prodrt_ethfb_qhd[CQUE] = xQueueCreateStatic(PRODRT_ETHFB_CTRL_QUE_LENGTH, PRODRT_ETHFB_CTRL_QUE_ITEMSIZE, prodrt_ethfb_ctrl_quearea, &prodrt_ethfb_ctrl_questru);
  configASSERT(prodrt_ethfb_qhd[CQUE]);

  /* 实时产量上传(AB服务器) 网络接收队列 */
  prodrt_ethfb_qhd[DQUE] = xQueueCreateStatic(PRODRT_ETHFB_DATA_QUE_LENGTH, PRODRT_ETHFB_DATA_QUE_ITEMSIZE, prodrt_ethfb_data_quearea, &prodrt_ethfb_data_questru);
  configASSERT(prodrt_ethfb_qhd[DQUE]);

  /* Modbus TCP 服务器 网络控制队列 */
  mbtcp_ethfb_qhd[CQUE] = xQueueCreateStatic(MBTCP_ETHFB_CTRL_QUE_LENGTH, MBTCP_ETHFB_CTRL_QUE_ITEMSIZE, mbtcp_ethfb_ctrl_quearea, &mbtcp_ethfb_ctrl_questru);
  configASSERT(mbtcp_ethfb_qhd[CQUE]);

  /* Modbus TCP 服务器 网络接收队列 */
  mbtcp_ethfb_qhd[DQUE] = xQueueCreateStatic(MBTCP_ETHFB_DATA_QUE_LENGTH, MBTCP_ETHFB_DATA_QUE_ITEMSIZE, mbtcp_ethfb_data_quearea, &mbtcp_ethfb_data_questru);
  configASSERT(mbtcp_ethfb_qhd[DQUE]);


  /* 以太网综合控制 队列集 */
  ethernet_qshd = xQueueCreateSet(ETHERNET_CTRL_QUE_LENGTH + ETHERNET_SEND_QUE_LENGTH + ETHERNET_ISR_QUE_LENGTH);
  configASSERT(ethernet_qshd);

  xQueueAddToSet(ethernet_ctrl_qhd, ethernet_qshd);
  xQueueAddToSet(ethernet_send_qhd, ethernet_qshd);
  xQueueAddToSet(ethernet_isr_qhd,  ethernet_qshd);

  /* 间隔产量以太网收发控制 队列集 */
  produp_ethfb_qshd = xQueueCreateSet(PRODUP_ETHFB_CTRL_QUE_LENGTH + PRODUP_ETHFB_DATA_QUE_LENGTH);
  configASSERT(produp_ethfb_qshd);

  xQueueAddToSet(produp_ethfb_qhd[CQUE], produp_ethfb_qshd);
  xQueueAddToSet(produp_ethfb_qhd[DQUE], produp_ethfb_qshd);

  /* 实时产量以太网收发控制 队列集 */
  prodrt_ethfb_qshd = xQueueCreateSet(PRODRT_ETHFB_CTRL_QUE_LENGTH + PRODRT_ETHFB_DATA_QUE_LENGTH);
  configASSERT(prodrt_ethfb_qshd);

  xQueueAddToSet(prodrt_ethfb_qhd[CQUE], prodrt_ethfb_qshd);
  xQueueAddToSet(prodrt_ethfb_qhd[DQUE], prodrt_ethfb_qshd);

  /* Modbus TCP 服务器以太网收发控制 队列集 */
  mbtcp_ethfb_qshd = xQueueCreateSet(MBTCP_ETHFB_CTRL_QUE_LENGTH + MBTCP_ETHFB_DATA_QUE_LENGTH);
  configASSERT(mbtcp_ethfb_qshd);

  xQueueAddToSet(mbtcp_ethfb_qhd[CQUE], mbtcp_ethfb_qshd);
  xQueueAddToSet(mbtcp_ethfb_qhd[DQUE], mbtcp_ethfb_qshd);
}
